import java.util.PriorityQueue;

/**
 * @program: LeetCode
 * @description: LeetCode : 剑指 Offer II 059. 数据流的第 K 大数值
 * @author: WXY
 * @create: 2022-12-31 16:31
 * @Version 1.0
 **/
public class Num_offer2_059_KthLargest {
    class KthLargest {
        public PriorityQueue heap = new PriorityQueue<Integer>();
        int k;

        public KthLargest(int k, int[] nums) {
            this.k = k;
            for (int i = 0; i < nums.length; i++) {
                heap.add(nums[i]);
            }
        }

        public int add(int val) {
            heap.add(val);
            while (heap.size() > k) {
                heap.poll();
            }
            return (int) heap.peek();
        }
    }

}
